package entities;

import java.util.ArrayList;
import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.hibernate.validator.constraints.Length;

import com.google.common.base.Objects;

@Entity()
@XmlRootElement 

public class Category extends Persistent {


	private String title = "";
	private List<Book> books = new ArrayList();

	@Transient
	private boolean editable;

	@Override
	public boolean equals(Object other) {
		if (other != null && other instanceof Category)
			return getTitle().equals(((Category) other).getTitle());
		return false;
	}
	@Override
	public int hashCode() {
		return getTitle().hashCode();
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@XmlTransient
	@OneToMany(mappedBy = "category", cascade = CascadeType.ALL)
	public List<Book> getBooks() {
		return this.books;
	}

	public void setBooks(List<Book> books) {
		this.books = books;
	}

	public String toString() {
		return this.title;
	}

	public void addBook(Book book) {
		books.add(book);
	}

	@Transient
	public boolean isEditable() {
		return editable;
	}

	@Transient
	public void setEditable(boolean editable) {
		this.editable = editable;
	}



}
